package views;

import java.util.Map;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Item;
import entity.TaskInfo;

public class TaskInfoCellModifier implements ICellModifier {
	  private Viewer viewer;

	  public TaskInfoCellModifier(Viewer viewer) {
	    this.viewer = viewer;
	  }

	  public boolean canModify(Object element, String property) {
	    return true;
	  }

	  public Object getValue(Object element, String property) {
		  TaskInfo p = (TaskInfo) element;
		  if (property.equals("description"))
			  return p.getDescription();
		  else if (property.equals("isActive"))
			  return p.isActive();
		  else if (property.equals("targetModule"))
			  return p.getTargetModule();
		  else if (property.equals("errors"))
			  return "no errors";
		  else if (property.equals("parameters"))
			  return p.getParameters();
		  else
			  return null;
	  }

	  public void modify(Object element, String property, Object value) {
	    if (element instanceof Item) element = ((Item) element).getData();

	    TaskInfo p = (TaskInfo) element;
	    if (property.equals("description"))
			  p.setDescription((String)value);
		  else if (property.equals("isActive"))
			  p.setActive((Boolean)value);
		  else if (property.equals("targetModule"))
			  p.setTargetModule((String)value);
		  //else if (property.equals("errors"))
			//  "no errors";
		  else if (property.equals("parameters"))
			  p.setParameters((Map<String,String>)value);
	    viewer.refresh();
	  }
	}
